<template>
  <div :class="messageClasses">
    <!-- 图标 -->
    <div v-if="showIcon && type !== 'hologram'" class="flex-shrink-0">
      <component :is="icon" class="h-4 w-4" :class="iconClasses" />
    </div>
    
    <!-- 内容 -->
    <div class="flex-1">
      <slot />
    </div>
    
    <!-- 额外信息 -->
    <div v-if="extraInfo && type !== 'hologram'" class="flex-shrink-0 ml-2">
      <UiBadge :variant="extraVariant" size="sm">
        {{ extraInfo }}
      </UiBadge>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { UiBadge } from './index'

interface Props {
  type?: 'info' | 'success' | 'warning' | 'error' | 'stats' | 'hologram'
  showIcon?: boolean
  extraInfo?: string
  extraVariant?: 'default' | 'secondary' | 'destructive' | 'outline' | 'hologram' | 'success' | 'warning' | 'info'
}

const props = withDefaults(defineProps<Props>(), {
  type: 'info',
  showIcon: true,
  extraVariant: 'secondary'
})

// 图标配置
const icon = computed(() => {
  const icons = {
    info: InfoIcon,
    success: SuccessIcon,
    warning: WarningIcon,
    error: ErrorIcon,
    stats: StatsIcon,
    hologram: HologramIcon
  }
  return icons[props.type]
})

// 样式配置
const typeConfig = computed(() => {
  const configs = {
    info: {
      bg: 'bg-background-800/30',
      border: 'border-background-600/30',
      text: 'text-text-secondary',
      iconClass: 'text-primary-400'
    },
    success: {
      bg: 'bg-success/20',
      border: 'border-success/30',
      text: 'text-success',
      iconClass: 'text-success'
    },
    warning: {
      bg: 'bg-warning/20',
      border: 'border-warning/30',
      text: 'text-warning',
      iconClass: 'text-warning'
    },
    error: {
      bg: 'bg-error/20',
      border: 'border-error/30',
      text: 'text-error',
      iconClass: 'text-error'
    },
    stats: {
      bg: 'bg-background-800/30',
      border: 'border-background-600/30',
      text: 'text-text-secondary',
      iconClass: 'text-primary-400'
    },
    hologram: {
      bg: 'bg-background-800/50',
      border: 'border-primary-400/30',
      text: 'text-primary-300',
      iconClass: 'text-primary-400'
    }
  }
  return configs[props.type]
})

const messageClasses = computed(() => {
  const config = typeConfig.value
  const baseClasses = [
    'px-3 py-2 rounded-lg border',
    config.bg,
    config.border,
    config.text
  ]
  
  // hologram类型使用垂直布局，其他使用水平布局
  if (props.type === 'hologram') {
    baseClasses.push('flex flex-col gap-2')
  } else {
    baseClasses.push('flex items-center gap-2')
  }
  
  return baseClasses
})

const iconClasses = computed(() => {
  return typeConfig.value.iconClass
})

// 图标组件
const InfoIcon = {
  template: `
    <svg fill="currentColor" viewBox="0 0 20 20">
      <path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd" />
    </svg>
  `
}

const SuccessIcon = {
  template: `
    <svg fill="currentColor" viewBox="0 0 20 20">
      <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd" />
    </svg>
  `
}

const WarningIcon = {
  template: `
    <svg fill="currentColor" viewBox="0 0 20 20">
      <path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />
    </svg>
  `
}

const ErrorIcon = {
  template: `
    <svg fill="currentColor" viewBox="0 0 20 20">
      <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd" />
    </svg>
  `
}

const StatsIcon = {
  template: `
    <svg fill="currentColor" viewBox="0 0 20 20">
      <path fill-rule="evenodd" d="M3 3a1 1 0 000 2v8a2 2 0 002 2h2.586l-1.293 1.293a1 1 0 101.414 1.414L10 15.414l2.293 2.293a1 1 0 001.414-1.414L12.414 14H15a2 2 0 002-2V5a1 1 0 100-2H3zm11.707 4.707a1 1 0 00-1.414-1.414L10 9.586 8.707 8.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd" />
    </svg>
  `
}

const HologramIcon = {
  template: `
    <svg fill="currentColor" viewBox="0 0 20 20">
      <path d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
    </svg>
  `
}
</script>
